﻿using TaobaoAPIDAO.App_Code;
using Top.Api.Domain;
using Top.Api.Response;
using Top.Api.Request;

namespace TaobaoAPIDAO.TopApiDao
{
    public class UserApiDao : BaseTopApiDao
    {
        #region public User GetUserInfoByNick(string Nick, string TopSessionKey) 通过单个Nick获取用户信息。
        /// <summary>
        /// 通过单个Nick获取用户信息。
        /// </summary>
        /// <param name="Nick">Nick</param>
        public User GetUserInfoByNick(string Nick, string TopSessionKey)
        {
            string xx1 = "<user_get_response>";
            string xx = "</user_get_response>";

            string aa = "<user>";
            string bb = "<User>";

            string aa1 = "</user>";
            string bb1 = "</User>";

            //实例化具体API对应的Request类 
            UserGetRequest req = new UserGetRequest();
            //需要查询的字段信息
            req.Fields = TaobaoAPIDAO.UserApiFiled.UserApiField;
            req.Nick = Nick;

            //执行API请求并将该类转换为response对象
            UserGetResponse response = myclient.Execute(req);
            User user = XmlHelper.LoadObjFromXMLForUser(response.Body.ToString().Replace(aa, bb).Replace(aa1, bb1).Replace(xx1, "").Replace(xx, ""));

            return user;
        }
        #endregion

        #region public UsersGetResponse GetUserInfoByNickList(string NickList) 通过多个Nick获取用户信息。
        /// <summary>
        /// 通过多个Nick获取用户信息
        /// </summary>
        /// <param name="NickList">NickList</param>
        public UsersGetResponse GetUserInfoByNickList(string NickList)
        {
            //实例化具体API对应的Request类 
            UsersGetRequest req = new UsersGetRequest();
            //需要查询的字段信息
            req.Fields = TaobaoAPIDAO.UserApiFiled.UserApiField;
            req.Nicks = NickList;

            UsersGetResponse response = myclient.Execute(req);
            return response;
        }
        #endregion

        #region public SellercenterSubusersGetResponse GetSubAccount(string Nick)根据Nick或者子帐号名称。
        /// <summary>
        /// 根据Nick或者子帐号名称
        /// </summary>
        /// <param name="Nick">Nick</param>
        /// <returns></returns>
        public SellercenterSubusersGetResponse GetSubAccount(string Nick, string TopSessionKey)
        {
            //实例化具体API对应的Request类 
            SellercenterSubusersGetRequest req = new SellercenterSubusersGetRequest();
            req.Nick = Nick;
            SellercenterSubusersGetResponse response = myclient.Execute(req, TopSessionKey);
            return response;
        }
        #endregion

        #region public Shop GetUserShopInfo(string Nick) 根据用户Nick取得该用的店铺信息
        /// <summary>
        /// 根据用户Nick取得该用的店铺信息
        /// </summary>
        /// <param name="Nick"></param>
        /// <returns></returns>
        public Shop GetUserShopInfo(string Nick)
        {
            string xx1 = "<shop_get_response>";
            string xx = "</shop_get_response>";

            string aa = "<shop>";
            string bb = "<Shop>";

            string aa1 = "</shop>";
            string bb1 = "</Shop>";

            ShopGetRequest req = new ShopGetRequest();
            req.Fields = ShopApiFiled.ShopApiField;
            req.Nick = Nick;
            ShopGetResponse response = myclient.Execute(req);
            Shop shop = XmlHelper.LoadObjFromXMLForShop(response.Body.ToString().Replace(aa, bb).Replace(aa1, bb1).Replace(xx1, "").Replace(xx, ""));
            return shop;
        }
        #endregion

    }
}